package com.zyk.scaffold.oauth.config.oauth.support;

import com.zyk.scaffold.oauth.component.TenantCodeCachComponent;
import com.zyk.scaffold.oauth.framework.domain.AccessToken;
import com.zyk.scaffold.oauth.framework.interfaces.ILoginCallBcak;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;

@Slf4j
public class LoginCallBcak implements ILoginCallBcak {
    private TenantCodeCachComponent tenantCodeCachComponent;
    public LoginCallBcak(TenantCodeCachComponent tenantCodeCachComponent) {
        this.tenantCodeCachComponent = tenantCodeCachComponent;
    }

    @Override
    public void success(AccessToken accessToken) {
        String account = accessToken.getAccount();
        String tenantCode = MapUtils.getString(accessToken.getData(), "tenantCode");
        log.info("login success, account:{}, tenantCode:{}", account, tenantCode);
        this.tenantCodeCachComponent.saveTenantCode(account, tenantCode);
    }
}
